#include "No7pch.h"
#include "OpenGLContext.h"

#include <GLFW/glfw3.h>
#include <glad/glad.h>

nmspc::OpenGLContext::OpenGLContext(GLFWwindow* window_handle) :
	window_handle(window_handle)
{
	NO7_CORE_ASSERT(window_handle, "Window handle is null!");
}

void nmspc::OpenGLContext::init()
{
	glfwMakeContextCurrent(this->window_handle);
	int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
	NO7_CORE_ASSERT(status, "Failed to initialize Glad!");
	NO7_CORE_LOG_INFO("OpenGL Info: ");
	NO7_CORE_LOG_INFO("  Vendor: {0}", static_cast<const char*>(static_cast<const void*>(glGetString(GL_VENDOR))));
	NO7_CORE_LOG_INFO("  Renderer: {0}", static_cast<const char*>(static_cast<const void*>(glGetString(GL_RENDERER))));
	NO7_CORE_LOG_INFO("  Version: {0}", static_cast<const char*>(static_cast<const void*>(glGetString(GL_VERSION))));
}

void nmspc::OpenGLContext::swapBuffers()
{
	glfwSwapBuffers(this->window_handle);
}
